package com.itheima;

import com.sun.source.tree.Tree;

import javax.sql.rowset.RowSetWarning;
import java.net.SocketTimeoutException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.TreeSet;

/**
 * @ProjectName: shixun DaErXia
 * @Titile: TreesetDemo
 * @Author: 雨
 * @Description: TODO
 */
public class TreesetDemo {
    public static void test1() {
        //集合只能存储引用数据类型
        TreeSet<Integer> set1=new TreeSet<>();
        //包装成integer对象 自动装箱
        set1.add(5);
        set1.add(4);
        set1.add(6);
        set1.add(7);
        set1.add(2);
        set1.add(1);
        for (Integer integer: set1);
        {
            System.out.println(set1);
        }

        TreeSet<Student> set=new TreeSet<>();
        set.add(new Student("luo1",19));
        set.add(new Student("luo2",20));
        set.add(new Student("luo3",21));
        set.add(new Student("luo4",22));

        for (Student student:set){
            System.out.println(student.getName()+"---"+student.getAge());

        }

    }
    public static void test2(){
       /**
           Comparator<Student> comparator=new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return 0;
            }
        };
        TreeSet<Student> set=new TreeSet<>();
**/
       Comparator<Student> comparator=(o1,o2)->o1.getAge()-o2.getAge();
        TreeSet<Student> set=new TreeSet();
        set.add(new Student("luo1",19));
        set.add(new Student("luo2",20));
        set.add(new Student("luo3",21));
        set.add(new Student("luo4",22));

        for (Student student:set){
            System.out.println(student.getName()+"---"+student.getAge());

        }
    }
    public static int sum(int...a){
        int total=0;
        for (int i=0;i<a.length;i++){
            total+=a[i];
        }
        return 0;
    }

}
